﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
using LibHuman;

namespace Human
{
	/// <summary>
	/// Summary description for frmBophan.
	/// </summary>
	public class frmBophan : System.Windows.Forms.Form
	{
		private AccessData  mDB=new AccessData();
        Language lan = new Language();
        string m_user = "";
        int co = 0;
        private DataSet ds = new DataSet();
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox txtMa;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.TextBox txtTen;
		private System.Windows.Forms.DataGrid dgrDanhMuc;
		private System.Windows.Forms.Label label3;
        private System.Windows.Forms.ComboBox cbonhom;
        private Label label4;
        private TextBox txtsott;
        private TextBox txt_sogiuong;
        private Label label5;
        private GroupBox groupBox1;
        private Button btn_them;
        private Button btn_sua;
        private Button btn_luu;
        private Button btn_boqua;
        private Button btn_xoa;
        private Button btn_thoat;
        private ComboBox cbo_khuvuc;
        private Label label6;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmBophan()
		{
			InitializeComponent();
            lan.Read_Language_to_Xml(this.Name.ToString(), this);
            lan.Changelanguage_to_English(this.Name.ToString(), this);
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmBophan));
            this.dgrDanhMuc = new System.Windows.Forms.DataGrid();
            this.label1 = new System.Windows.Forms.Label();
            this.txtMa = new System.Windows.Forms.TextBox();
            this.label2 = new System.Windows.Forms.Label();
            this.txtTen = new System.Windows.Forms.TextBox();
            this.label3 = new System.Windows.Forms.Label();
            this.cbonhom = new System.Windows.Forms.ComboBox();
            this.label4 = new System.Windows.Forms.Label();
            this.txtsott = new System.Windows.Forms.TextBox();
            this.txt_sogiuong = new System.Windows.Forms.TextBox();
            this.label5 = new System.Windows.Forms.Label();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.btn_boqua = new System.Windows.Forms.Button();
            this.btn_thoat = new System.Windows.Forms.Button();
            this.btn_xoa = new System.Windows.Forms.Button();
            this.btn_luu = new System.Windows.Forms.Button();
            this.btn_sua = new System.Windows.Forms.Button();
            this.btn_them = new System.Windows.Forms.Button();
            this.cbo_khuvuc = new System.Windows.Forms.ComboBox();
            this.label6 = new System.Windows.Forms.Label();
            ((System.ComponentModel.ISupportInitialize)(this.dgrDanhMuc)).BeginInit();
            this.groupBox1.SuspendLayout();
            this.SuspendLayout();
            // 
            // dgrDanhMuc
            // 
            this.dgrDanhMuc.AlternatingBackColor = System.Drawing.Color.Lavender;
            this.dgrDanhMuc.BackColor = System.Drawing.Color.WhiteSmoke;
            this.dgrDanhMuc.BackgroundColor = System.Drawing.SystemColors.Control;
            this.dgrDanhMuc.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.dgrDanhMuc.CaptionBackColor = System.Drawing.Color.LightSteelBlue;
            this.dgrDanhMuc.CaptionForeColor = System.Drawing.Color.MidnightBlue;
            this.dgrDanhMuc.CaptionVisible = false;
            this.dgrDanhMuc.DataMember = "";
            this.dgrDanhMuc.FlatMode = true;
            this.dgrDanhMuc.Font = new System.Drawing.Font("Tahoma", 8F);
            this.dgrDanhMuc.ForeColor = System.Drawing.Color.MidnightBlue;
            this.dgrDanhMuc.GridLineColor = System.Drawing.Color.Gainsboro;
            this.dgrDanhMuc.GridLineStyle = System.Windows.Forms.DataGridLineStyle.None;
            this.dgrDanhMuc.HeaderBackColor = System.Drawing.Color.MidnightBlue;
            this.dgrDanhMuc.HeaderFont = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Bold);
            this.dgrDanhMuc.HeaderForeColor = System.Drawing.Color.WhiteSmoke;
            this.dgrDanhMuc.LinkColor = System.Drawing.Color.Teal;
            this.dgrDanhMuc.Location = new System.Drawing.Point(8, 8);
            this.dgrDanhMuc.Name = "dgrDanhMuc";
            this.dgrDanhMuc.ParentRowsBackColor = System.Drawing.Color.Gainsboro;
            this.dgrDanhMuc.ParentRowsForeColor = System.Drawing.Color.MidnightBlue;
            this.dgrDanhMuc.RowHeaderWidth = 10;
            this.dgrDanhMuc.SelectionBackColor = System.Drawing.Color.CadetBlue;
            this.dgrDanhMuc.SelectionForeColor = System.Drawing.Color.WhiteSmoke;
            this.dgrDanhMuc.Size = new System.Drawing.Size(596, 318);
            this.dgrDanhMuc.TabIndex = 4;
            this.dgrDanhMuc.CurrentCellChanged += new System.EventHandler(this.dgrDanhmuc_CurrentCellChanged);
            // 
            // label1
            // 
            this.label1.BackColor = System.Drawing.SystemColors.Control;
            this.label1.ForeColor = System.Drawing.Color.DarkBlue;
            this.label1.Location = new System.Drawing.Point(3, 332);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(22, 13);
            this.label1.TabIndex = 109;
            this.label1.Text = "Mã";
            this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // txtMa
            // 
            this.txtMa.BackColor = System.Drawing.Color.White;
            this.txtMa.Enabled = false;
            this.txtMa.ForeColor = System.Drawing.Color.DarkBlue;
            this.txtMa.Location = new System.Drawing.Point(6, 348);
            this.txtMa.Name = "txtMa";
            this.txtMa.Size = new System.Drawing.Size(44, 20);
            this.txtMa.TabIndex = 0;
            this.txtMa.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
            // 
            // label2
            // 
            this.label2.BackColor = System.Drawing.SystemColors.Control;
            this.label2.ForeColor = System.Drawing.Color.DarkBlue;
            this.label2.Location = new System.Drawing.Point(61, 330);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(94, 13);
            this.label2.TabIndex = 111;
            this.label2.Text = "Tên khoa/phòng :";
            this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // txtTen
            // 
            this.txtTen.BackColor = System.Drawing.Color.White;
            this.txtTen.ForeColor = System.Drawing.Color.DarkBlue;
            this.txtTen.Location = new System.Drawing.Point(64, 348);
            this.txtTen.MaxLength = 30;
            this.txtTen.Name = "txtTen";
            this.txtTen.Size = new System.Drawing.Size(152, 20);
            this.txtTen.TabIndex = 1;
            this.txtTen.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtTen_KeyDown);
            // 
            // label3
            // 
            this.label3.BackColor = System.Drawing.SystemColors.Control;
            this.label3.ForeColor = System.Drawing.Color.DarkBlue;
            this.label3.Location = new System.Drawing.Point(230, 329);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(41, 13);
            this.label3.TabIndex = 113;
            this.label3.Text = "Nhóm :";
            this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // cbonhom
            // 
            this.cbonhom.Items.AddRange(new object[] {
            "Khoa lâm sàng",
            "Khoa cận lâm sàng",
            "Các phòng ban",
            "Nhóm y tế dự phòng",
            "Nhóm y tế xã phường",
            "Khác"});
            this.cbonhom.Location = new System.Drawing.Point(233, 347);
            this.cbonhom.Name = "cbonhom";
            this.cbonhom.Size = new System.Drawing.Size(131, 21);
            this.cbonhom.TabIndex = 2;
            this.cbonhom.KeyDown += new System.Windows.Forms.KeyEventHandler(this.cbonhom_KeyDown);
            // 
            // label4
            // 
            this.label4.ForeColor = System.Drawing.Color.DarkBlue;
            this.label4.Location = new System.Drawing.Point(491, 329);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(53, 13);
            this.label4.TabIndex = 114;
            this.label4.Text = "Số thứ tự:";
            this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // txtsott
            // 
            this.txtsott.BackColor = System.Drawing.Color.White;
            this.txtsott.ForeColor = System.Drawing.Color.DarkBlue;
            this.txtsott.Location = new System.Drawing.Point(494, 348);
            this.txtsott.Name = "txtsott";
            this.txtsott.Size = new System.Drawing.Size(50, 20);
            this.txtsott.TabIndex = 4;
            this.txtsott.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
            this.txtsott.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtsott_KeyDown);
            this.txtsott.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtsott_KeyPress);
            // 
            // txt_sogiuong
            // 
            this.txt_sogiuong.BackColor = System.Drawing.Color.White;
            this.txt_sogiuong.ForeColor = System.Drawing.Color.DarkBlue;
            this.txt_sogiuong.Location = new System.Drawing.Point(549, 348);
            this.txt_sogiuong.Name = "txt_sogiuong";
            this.txt_sogiuong.Size = new System.Drawing.Size(53, 20);
            this.txt_sogiuong.TabIndex = 5;
            this.txt_sogiuong.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
            this.txt_sogiuong.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txt_sogiuong_KeyDown);
            this.txt_sogiuong.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txt_sogiuong_KeyPress);
            // 
            // label5
            // 
            this.label5.ForeColor = System.Drawing.Color.DarkBlue;
            this.label5.Location = new System.Drawing.Point(546, 329);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(58, 13);
            this.label5.TabIndex = 114;
            this.label5.Text = "Số giường:";
            this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.btn_boqua);
            this.groupBox1.Controls.Add(this.btn_thoat);
            this.groupBox1.Controls.Add(this.btn_xoa);
            this.groupBox1.Controls.Add(this.btn_luu);
            this.groupBox1.Controls.Add(this.btn_sua);
            this.groupBox1.Controls.Add(this.btn_them);
            this.groupBox1.Location = new System.Drawing.Point(45, 368);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(467, 47);
            this.groupBox1.TabIndex = 115;
            this.groupBox1.TabStop = false;
            // 
            // btn_boqua
            // 
            this.btn_boqua.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_boqua.ForeColor = System.Drawing.Color.DarkBlue;
            this.btn_boqua.Image = global::Human.Properties.Resources.undo_2005;
            this.btn_boqua.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_boqua.Location = new System.Drawing.Point(236, 13);
            this.btn_boqua.Name = "btn_boqua";
            this.btn_boqua.Size = new System.Drawing.Size(65, 28);
            this.btn_boqua.TabIndex = 3;
            this.btn_boqua.Text = "&Bỏ qua";
            this.btn_boqua.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.btn_boqua.UseVisualStyleBackColor = true;
            this.btn_boqua.Click += new System.EventHandler(this.btn_boqua_Click);
            // 
            // btn_thoat
            // 
            this.btn_thoat.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_thoat.ForeColor = System.Drawing.Color.DarkBlue;
            this.btn_thoat.Image = global::Human.Properties.Resources.close_r1;
            this.btn_thoat.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_thoat.Location = new System.Drawing.Point(367, 13);
            this.btn_thoat.Name = "btn_thoat";
            this.btn_thoat.Size = new System.Drawing.Size(60, 28);
            this.btn_thoat.TabIndex = 5;
            this.btn_thoat.Text = "&Thoát";
            this.btn_thoat.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.btn_thoat.UseVisualStyleBackColor = true;
            this.btn_thoat.Click += new System.EventHandler(this.btn_thoat_Click);
            // 
            // btn_xoa
            // 
            this.btn_xoa.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_xoa.ForeColor = System.Drawing.Color.DarkBlue;
            this.btn_xoa.Image = global::Human.Properties.Resources.delete_enabled;
            this.btn_xoa.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_xoa.Location = new System.Drawing.Point(304, 13);
            this.btn_xoa.Name = "btn_xoa";
            this.btn_xoa.Size = new System.Drawing.Size(60, 28);
            this.btn_xoa.TabIndex = 4;
            this.btn_xoa.Text = "   &Xóa";
            this.btn_xoa.UseVisualStyleBackColor = true;
            this.btn_xoa.Click += new System.EventHandler(this.btn_xoa_Click);
            // 
            // btn_luu
            // 
            this.btn_luu.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_luu.ForeColor = System.Drawing.Color.DarkBlue;
            this.btn_luu.Image = global::Human.Properties.Resources.save;
            this.btn_luu.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_luu.Location = new System.Drawing.Point(174, 13);
            this.btn_luu.Name = "btn_luu";
            this.btn_luu.Size = new System.Drawing.Size(60, 28);
            this.btn_luu.TabIndex = 2;
            this.btn_luu.Text = "   &Lưu";
            this.btn_luu.UseVisualStyleBackColor = true;
            this.btn_luu.Click += new System.EventHandler(this.btn_luu_Click);
            // 
            // btn_sua
            // 
            this.btn_sua.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_sua.ForeColor = System.Drawing.Color.DarkBlue;
            this.btn_sua.Image = global::Human.Properties.Resources.quick_edit;
            this.btn_sua.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_sua.Location = new System.Drawing.Point(111, 13);
            this.btn_sua.Name = "btn_sua";
            this.btn_sua.Size = new System.Drawing.Size(60, 28);
            this.btn_sua.TabIndex = 1;
            this.btn_sua.Text = "   &Sửa";
            this.btn_sua.UseVisualStyleBackColor = true;
            this.btn_sua.Click += new System.EventHandler(this.btn_sua_Click);
            // 
            // btn_them
            // 
            this.btn_them.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btn_them.ForeColor = System.Drawing.Color.DarkBlue;
            this.btn_them.Image = global::Human.Properties.Resources.add;
            this.btn_them.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_them.Location = new System.Drawing.Point(48, 13);
            this.btn_them.Name = "btn_them";
            this.btn_them.Size = new System.Drawing.Size(60, 28);
            this.btn_them.TabIndex = 0;
            this.btn_them.Text = "   &Thêm";
            this.btn_them.UseVisualStyleBackColor = true;
            this.btn_them.Click += new System.EventHandler(this.btn_them_Click);
            // 
            // cbo_khuvuc
            // 
            this.cbo_khuvuc.FormattingEnabled = true;
            this.cbo_khuvuc.Items.AddRange(new object[] {
            "Khu vực thường ",
            "Khu vực hồi sức"});
            this.cbo_khuvuc.Location = new System.Drawing.Point(381, 347);
            this.cbo_khuvuc.Name = "cbo_khuvuc";
            this.cbo_khuvuc.Size = new System.Drawing.Size(91, 21);
            this.cbo_khuvuc.TabIndex = 3;
            this.cbo_khuvuc.KeyDown += new System.Windows.Forms.KeyEventHandler(this.cbo_khuvuc_KeyDown);
            // 
            // label6
            // 
            this.label6.BackColor = System.Drawing.SystemColors.Control;
            this.label6.ForeColor = System.Drawing.Color.DarkBlue;
            this.label6.Location = new System.Drawing.Point(378, 330);
            this.label6.Name = "label6";
            this.label6.Size = new System.Drawing.Size(69, 16);
            this.label6.TabIndex = 113;
            this.label6.Text = "Khu vực:";
            this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // frmBophan
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(612, 416);
            this.Controls.Add(this.cbo_khuvuc);
            this.Controls.Add(this.groupBox1);
            this.Controls.Add(this.label5);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.cbonhom);
            this.Controls.Add(this.label6);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.txt_sogiuong);
            this.Controls.Add(this.txtTen);
            this.Controls.Add(this.txtsott);
            this.Controls.Add(this.txtMa);
            this.Controls.Add(this.dgrDanhMuc);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "frmBophan";
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Danh mục bộ phận";
            this.Load += new System.EventHandler(this.frmBophan_Load);
            ((System.ComponentModel.ISupportInitialize)(this.dgrDanhMuc)).EndInit();
            this.groupBox1.ResumeLayout(false);
            this.ResumeLayout(false);
            this.PerformLayout();

		}
		#endregion

		
		private void Ena_control(bool ena)
		{
			btn_them.Enabled=ena;
			btn_sua.Enabled=ena;
			btn_luu.Enabled=!ena;
			btn_boqua.Enabled=!ena;
			btn_xoa.Enabled=ena;
			btn_thoat.Enabled=ena;
		}
		private void Ena_textbox(bool ena)
		{
            txtsott.Enabled = ena;
            txtTen.Enabled=ena;
			cbonhom.Enabled =ena;
            txtsott.Enabled = ena;
            txt_sogiuong.Enabled = ena;
            cbo_khuvuc.Enabled = ena;
		}
		private void clear_Text()
		{			
			txtTen.Clear();
		}
		private void refresh_Text()
		{
            try
            {
                string a = "",kv = "";
                int i = dgrDanhMuc.CurrentRowIndex;
                if (i >= 0)
                {
                    txtMa.Text = dgrDanhMuc[i, 0].ToString();
                    txtTen.Text = dgrDanhMuc[i, 1].ToString();
                    a = dgrDanhMuc[i, 2].ToString().Trim();
                    if (a == "Khoa lâm sàng")
                        cbonhom.SelectedIndex = 0;
                    else
                        if (a == "Khoa cận lâm sàng")
                            cbonhom.SelectedIndex = 1;
                        else
                            if (a == "Các phòng ban")
                                cbonhom.SelectedIndex = 2;
                                else
                                if (a == "Y tế dự phòng")
                                    cbonhom.SelectedIndex = 3;
                                else
                                    if (a == "Y tế phường xã")
                                        cbonhom.SelectedIndex = 4;
                            else
                                cbonhom.SelectedIndex = 5;
            
            kv = dgrDanhMuc[i, 6].ToString().Trim();
            if (kv == "Khu vực thường")
                cbo_khuvuc.SelectedIndex = 0;
            else
                if (kv == "Khu vực hồi sức")
                    cbo_khuvuc.SelectedIndex = 1;
                    txtsott.Text = dgrDanhMuc[i, 3].ToString().Trim();
                    txt_sogiuong.Text = dgrDanhMuc[i, 5].ToString().Trim();
                }
            }
            catch { }  		
		}
		private void frmBophan_Load(object sender, System.EventArgs e)
		{
			bophan();			
			Ena_control(true);
            btn_sua.Enabled = false;
            btn_xoa.Enabled = false;
			refresh_Text();
			Ena_textbox(false);
			btn_them.Focus();
		}
		private void bophan()
		{
            string sql = "";
            sql=" SELECT madv,tenbp,sothutu,sogiuong, ";
	        sql += " CASE substring(mabsoft,1,1) ";
	        sql += " WHEN 'C' THEN 'Khoa cận lâm sàng' ";
            sql += " WHEN 'L' THEN 'Khoa lâm sàng' ";
	        sql += " WHEN 'P' THEN 'Các phòng ban' ";
            sql += " WHEN 'D' THEN 'Y tế dự phòng' ";
            sql += " WHEN 'X' THEN 'Y tế phường xã' ";
            sql += " ELSE 'khác'   END as masoft,sothutu ";
            sql += " ,case when khuvuc='KT' then 'Khu vực thường' when khuvuc='HS' then 'Khu vực hồi sức' else '' end as khuvuc";
            sql += " FROM " + mDB.user + ".bophan order by sothutu ";
            DataSet ds1=new DataSet();
			ds1=mDB.get_data(sql);
			dgrDanhMuc.DataSource=null;
			dgrDanhMuc.TableStyles.Clear();
			DataGridTableStyle ts = new DataGridTableStyle();
			ts.MappingName = ds1.Tables[0].TableName;
		
			ts.AlternatingBackColor = Color.Beige;
			ts.BackColor = Color.GhostWhite;
			ts.ForeColor = Color.MidnightBlue;
			ts.GridLineColor = Color.RoyalBlue;
			ts.HeaderBackColor = Color.MidnightBlue;
			ts.HeaderForeColor = Color.Lavender;
			ts.SelectionBackColor = Color.Teal;
			ts.SelectionForeColor = Color.PaleGreen;
			
			DataGridTextBoxColumn TextCol1=new DataGridTextBoxColumn();
			TextCol1.MappingName = "madv";
			TextCol1.HeaderText = lan.Change_language_MessageText("Mã bộ phận");
			TextCol1.Width = 80;
			TextCol1.ReadOnly=true;
			TextCol1.Alignment=HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(TextCol1);
			dgrDanhMuc.TableStyles.Add(ts);
		
			DataGridTextBoxColumn TextCol2=new DataGridTextBoxColumn();
			TextCol2.MappingName = "tenbp";
			TextCol2.HeaderText = lan.Change_language_MessageText("Tên bộ phận");
			TextCol2.Width = 180;
			TextCol2.ReadOnly=true;
			TextCol2.Alignment=HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(TextCol2);
			dgrDanhMuc.TableStyles.Add(ts);	

			DataGridTextBoxColumn TextCol3=new DataGridTextBoxColumn();
			TextCol3.MappingName = "masoft";
			TextCol3.HeaderText = lan.Change_language_MessageText("Nhóm khoa");
			TextCol3.Width = 120;
			TextCol3.ReadOnly=true;
			TextCol3.Alignment=HorizontalAlignment.Left;
			ts.GridColumnStyles.Add(TextCol3);
			dgrDanhMuc.TableStyles.Add(ts);

            DataGridTextBoxColumn TextCol4 = new DataGridTextBoxColumn();
            TextCol4.MappingName = "sothutu";
            TextCol4.HeaderText = lan.Change_language_MessageText("Số TT");
            TextCol4.Width = 40;
            TextCol4.ReadOnly = true;
            TextCol4.Alignment = HorizontalAlignment.Center;
            ts.GridColumnStyles.Add(TextCol4);
            dgrDanhMuc.TableStyles.Add(ts);

            DataGridTextBoxColumn TextCol5 = new DataGridTextBoxColumn();
            TextCol5.MappingName = "sogiuong";
            TextCol5.HeaderText = lan.Change_language_MessageText("Số Giường");
            TextCol5.Width = 40;
            TextCol5.ReadOnly = true;
            TextCol5.Alignment = HorizontalAlignment.Center;
            ts.GridColumnStyles.Add(TextCol5);
            dgrDanhMuc.TableStyles.Add(ts);

            DataGridTextBoxColumn TextCol6 = new DataGridTextBoxColumn();
            TextCol6.MappingName = "khuvuc";
            TextCol6.HeaderText = lan.Change_language_MessageText("Khu vực");
            TextCol6.Width = 100;
            TextCol6.ReadOnly = true;
            TextCol6.Alignment = HorizontalAlignment.Center;
            ts.GridColumnStyles.Add(TextCol6);
            dgrDanhMuc.TableStyles.Add(ts);

			ts.DataGrid.DataSource=ds1.Tables[0];
            CurrencyManager cm = (CurrencyManager)BindingContext[dgrDanhMuc.DataSource, dgrDanhMuc.DataMember];
            DataView dv = (DataView)cm.List;
            dv.AllowNew = false;
            dv.AllowEdit = false;
            dv.AllowDelete = false;
		}

		private void dgrDanhmuc_CurrentCellChanged(object sender, System.EventArgs e)
		{
			try
			{
				refresh_Text();
				Ena_textbox(false);
				Ena_control(true);
                btn_them.Enabled = false;
                btn_boqua.Enabled = true;
			}
			catch{}
		}

		private void txtTen_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
            if (e.KeyCode == Keys.Enter)
			{
				cbonhom.Focus();
				SendKeys.Send("{F4}");
			}
		}

		private void btnLuu_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Enter)
			{
				btn_them.Focus();
			}
		}

		private void btnKetthuc_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void cbonhom_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
            if (e.KeyCode == Keys.Enter)
                SendKeys.Send("{Tab}{F4}");
		}

        private void txtsott_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((e.KeyChar < '0' || e.KeyChar > '9') && e.KeyChar != '\b')
                e.KeyChar = '\0';
        }
        private void cbo_khuvuc_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                txtsott.Focus();
        }
        private void txtsott_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                txt_sogiuong.Focus();
        }

        private void txt_sogiuong_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                btn_luu.Focus();
        }

        private void txt_sogiuong_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((e.KeyChar < '0' || e.KeyChar > '9') && e.KeyChar != '\b')
                e.KeyChar = '\0';
        }

        private bool kemtra(string madv)
        {
            bool flag = false;
            try
            {
                flag = mDB.get_data("select count(*) as tong from " + mDB.user + ".llnv where madv='" + madv + "'").Tables[0].Rows[0][0].ToString().Equals("0");
            }
            catch
            {
                flag = false;
            }
            if (!flag)
                MessageBox.Show(lan.Change_language_MessageText("Bô phận đã có nhân viên không thể hủy!"),AccessData.Msg);
            return flag;
        }
        private string get_maxid()
        {
            int m_tam;
            ds = mDB.get_data("SELECT Max(to_number(madv,999)) FROM " + m_user + ".bophan");
            if (ds.Tables[0].Rows[0][0].ToString() == "")
            {
                m_tam = 1;
            }
            else
            {
                m_tam = int.Parse(ds.Tables[0].Rows[0][0].ToString());
                m_tam += 1;
            }
             return m_tam.ToString().PadLeft(3, '0').ToString();//txtsott.Text = txtMa.Text
        }
        private void btn_them_Click(object sender, EventArgs e)
        {
            co = 0;
            Ena_control(false);
            Ena_textbox(true);
            clear_Text();
            m_user = mDB.user;
            txtMa.Text = get_maxid();
            txtTen.Focus();
        }

        private void btn_sua_Click(object sender, EventArgs e)
        {
            co = 1;
            Ena_control(false);
            Ena_textbox(true);
            txtTen.Focus();
        }

        private void btn_luu_Click(object sender, EventArgs e)
        {
            int m_id = 0;
            try
            {
                string a = "",kv="";
                if (cbonhom.SelectedIndex == 0)
                    a = "L";
                else
                    if (cbonhom.SelectedIndex == 1)
                        a = "C";
                    else
                        if (cbonhom.SelectedIndex == 2)
                            a = "P";
                        else
                            if (cbonhom.SelectedIndex == 3)
                                a = "D";
                            else
                                if (cbonhom.SelectedIndex == 4)
                                    a = "X";
                                else
                                    a = "K";
                if (cbo_khuvuc.SelectedIndex == 0)
                    kv = "KT";
                else
                    if (cbo_khuvuc.SelectedIndex == 1)
                        kv = "HS";
                decimal stt = txtsott.Text.Trim() != "" ? decimal.Parse(txtsott.Text.Trim()) : 0;
                string sogiuong = txt_sogiuong.Text.Trim() != "" ? txt_sogiuong.Text.Trim() : "0";
                if (co == 0)
                {
                    m_id = Int32.Parse(get_maxid());
                    txtMa.Text=m_id.ToString().PadLeft(3,'0');
                }
                else
                {
                    if (txtMa.Text != "")
                        m_id = Int32.Parse(txtMa.Text.ToString());
                }
                mDB.Insert_DMBOPHAN(txtMa.Text, txtTen.Text, a, stt, sogiuong,kv);
                bophan();
                co = 0;
                Ena_control(true);
                btn_xoa.Enabled = false;
                btn_sua.Enabled = false;
                Ena_textbox(false);
                btn_them.Focus();
            }
            catch { }
        }

        private void btn_boqua_Click(object sender, EventArgs e)
        {
            Ena_control(true);
            Ena_textbox(false);
            btn_xoa.Enabled = false;
            btn_sua.Enabled = false;
            txtTen.Enabled = false;
            refresh_Text();
            btn_thoat.Focus();
        }

        private void btn_xoa_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show(lan.Change_language_MessageText("Đồng ý huỷ bộ phận này?"),AccessData.Msg, MessageBoxButtons.YesNo);
            if (dr == DialogResult.Yes && kemtra(txtMa.Text.Trim()))
            {
                mDB.get_data("DELETE  FROM " + mDB.user + ".bophan WHERE madv='" + txtMa.Text.Trim() + "'");
            }
            bophan();
            refresh_Text();
            btn_xoa.Enabled = false;
            btn_sua.Enabled = false;
        }

        private void btn_thoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        
	}
}
